package com.stockz.ui.swing.scanner;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

import com.stockz.core.model.Scrip;
import com.stockz.ui.swing.charting.view.StockChartView;
import com.stockz.ui.swing.core.MainFrame;

public class ScanResultPanel extends JPanel {
	private static final long serialVersionUID = -2516273046292749412L;
	private JTable table;

	public ScanResultPanel() {
		setLayout(new BorderLayout(0, 0));
		
		JPanel controlPanel = new JPanel();
		add(controlPanel, BorderLayout.NORTH);
		
		JButton chartButton = new JButton("Chart");
		chartButton.addActionListener(new ActionListener(){
			@SuppressWarnings("unchecked")
			@Override
			public void actionPerformed(ActionEvent e) {
				if(table.getSelectedRowCount() > 0){
					DefaultTableModel atm = (DefaultTableModel)getTable().getModel();
					List<Scrip> scripList = new ArrayList<Scrip>();
					Vector<Vector<Scrip>> dataVector = atm.getDataVector();
					for(Vector<Scrip> vector : dataVector){
						scripList.add(vector.get(0));
					}
					MainFrame.getInstance().add(new StockChartView(scripList));
				}
			}
		});
		controlPanel.add(chartButton);
		
		JButton watchListButton = new JButton("Add to WatchList");
		controlPanel.add(watchListButton);
		
		Component horizontalGlue = Box.createHorizontalGlue();
		controlPanel.add(horizontalGlue);
		
		JLabel selectLabel = new JLabel("Select");
		controlPanel.add(selectLabel);
		
		JButton allButton = new JButton("All");
		allButton.addActionListener(new ActionListener(){
			@Override
			public void actionPerformed(ActionEvent e) {
				table.selectAll();
			}
		});
		controlPanel.add(allButton);
		
		JButton noneButton = new JButton("None");
		noneButton.addActionListener(new ActionListener(){
			@Override
			public void actionPerformed(ActionEvent e) {
				table.clearSelection();
			}
		});
		controlPanel.add(noneButton);
		
		table = new JTable();
		Vector<String> columnNameVector = new Vector<String>();
		columnNameVector.add("Scan Results");
		table.setModel(new DefaultTableModel(new String[]{"Scan Results"},0));
		table.setShowVerticalLines(false);
		JScrollPane scrollPane = new JScrollPane(table);
		table.setFillsViewportHeight(true);
		add(scrollPane, BorderLayout.CENTER);
		
	}

/*	public void addRow(Scrip scrip){
		table.getModel()
	}*/
	
	public JTable getTable() {
		return table;
	}


	public void setTable(JTable table) {
		this.table = table;
	}



}
